/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.lcfgly.Service;

import com.lcfgly.Dao.OnepageImpl;
import com.lcfgly.Database.ShopOnepage;
import com.lcfgly.Exception.ActionException;
import com.lcfgly.Exception.ErrorException;
import com.lcfgly.Exception.SQLEmptyException;
import java.io.Serializable;
import java.sql.SQLException;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 单页文档服务
 * @author lcfgly
 */
@Service
public class OnepageService implements Serializable{
    
    Logger log=Logger.getLogger("SqlError");
    
    @Autowired
    OnepageImpl onepageImpl;
    
    /**
     * 更新单页文档
     * @param onepage
     * @param userid
     * @throws ActionException 
     */
    public void updateonepage(ShopOnepage onepage,int userid) throws ActionException{
        try {
            onepageImpl.updateWithWriteruid(onepage, userid);
        } catch (SQLException ex) {
            log.error(ex);
            throw new ErrorException();
        }
    }
    
    /**
     * 通过ID获取单页内容
     * @param id
     * @return
     * @throws ActionException 
     */
    public ShopOnepage findById(Integer id) throws ActionException{
        try{
            return onepageImpl.findById(id);
        }catch(SQLEmptyException e){
            log.error(e);
            throw new ActionException("未查找到先关数据");
        }catch(SQLException e){
            log.error(e);
            throw new ErrorException();
        }
    }
    
}
